import { ref, onMounted } from 'vue';
import { useDictStore } from '@/stores/dict';

export function useDict(...dictTypes: string[]) {
  const dictStore = useDictStore();
  const dicts = ref<Record<string, any[]>>({});

  const load = async () => {
    for (const type of dictTypes) {
      dicts.value[type] = await dictStore.getDict(type);
    }
  };

  onMounted(load);

  return {
    dicts,
    load, // 重新加载
    refresh: (type: string) => dictStore.refresh(type),
  };
}
